<?php
/* SVN FILE: $Id: plugin.php 246 2009-10-21 05:25:31Z supersmashbrothers $ */
/**
* ibMarket 2
* IP.Board 3.0
* Admin Plugin Ajax
*
* @author $Author: supersmashbrothers $
* @copyright $Copyright$
* @version $Revision: 246 $
* @lastrevision $Date: 2009-10-21 05:25:31 +0000 (Wed, 21 Oct 2009) $
* @modifiedby $LastChangedBy: supersmashbrothers $
* @lastmodified $LastChangedDate: 2009-10-21 05:25:31 +0000 (Wed, 21 Oct 2009) $
* @filesource $URL: http://ipb-ibmarket.googlecode.com/svn/ibmarket2/trunk/admin/applications_addon/other/ibmarket/modules_public/ajax/plugin.php $
*/


if ( ! defined( 'IN_IPB' ) )
{
	print "<h1>Incorrect access</h1>You cannot access this file directly. If you have recently upgraded, make sure you upgraded all the relevant files.";
	exit();
}

class public_ibmarket_ajax_plugin extends ipsAjaxCommand
{
	/**
	* Main class entry point
	*
	* @access	public
	* @param	object		ipsRegistry reference
	* @return	void		[Outputs to screen]
	*/
	public function doExecute( ipsRegistry $registry )
	{
		if(!is_array($this->caches['market_plugin'][$this->request['plugin']]))
		{
			$this->returnJsonError( 'cannot_find_plugin' );
		}
		
		if(file_exists(IPSLib::getAppDir('ibmarket')."/plugins/".$this->request['plugin']."/publicAjax/".$this->request['action'].".php"))
		{
			require_once(IPSLib::getAppDir('ibmarket')."/plugins/".$this->request['plugin']."/publicAjax/".$this->request['action'].".php");
		}
		
		$class = 'plugin_ajax_public_'.$this->request['plugin'].'_'.$this->request['action'];
		if(class_exists($class))
		{
			$cmd_class = new ReflectionClass( $class );
			
			if ( $cmd_class->isSubClassOf( 'ipsAjaxCommand' ) )
			{
				$cmd_class->newInstance()->execute( $this->registry );
				return;
			}
		}
		
		$this->returnJsonError( 'cannot_find_plugin' );
	}
}